package com.htj.erp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.htj.erp.model.mybatis.OrderbPO;
import com.htj.erp.service.OrderbService;
import com.htj.erp.vo.OrderbVO;
import com.kedacom.utils.ArrayUtil;
import com.kedacom.utils.RequestUtil;
import com.kedacom.web.ResultMessage;
import com.kedacom.web.controller.BaseController;

/**
 * 
 * 
 * orderb的界面处理controller
 * OrderbController
 * 继承com.kedacom.web.controller.BaseController 
 * chenghongtao
 * 2016-11-07 15:30:51
 * HTJ
 * 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping({ "/platform/orderb" })
public class OrderbController extends BaseController {

	@Resource
	private OrderbService orderbService;

	/**
	 * 
	 * page 列表页面
	 * @return
	 * @throws Exception
	 *ModelAndView
	 * @exception
	 * @since  1.0.0
	 */
	@RequestMapping("/page.do")
	public ModelAndView page() throws Exception {
		return getAutoView();
	}

	/**
	 * 
	 * listData 查询所有数据 通过界面查询
	 * @param pageable
	 * @return
	 * @throws Exception
	 *Page<OrderbPO>
	 * @exception
	 * @since  1.0.0
	 */
	@RequestMapping("/listAllData.do")
	@ResponseBody
	public List<OrderbVO> listAllData() throws Exception
	{
		return orderbService.getAll(RequestUtil.getParameterValueMap(request, false,false));
	}

	/**
	 * 编辑界面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editForm.do")
	public ModelAndView editForm(Long id) throws Exception
	{
		if(id== null || id==0)
		{
			this.response.sendRedirect("addForm.do");
			return null;
		}
		else
		{
			return this.getAutoView().addObject("vo", this.orderbService.getById(id));
		}
	}

	@RequestMapping("/addForm.do")
	public ModelAndView addForm() throws Exception
	{

		return this.getAutoView();
	}
	/**
	 * 查看界面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/view.do")
	public ModelAndView view(Long id) throws Exception
	{
		if(id== null || id==0)
		{
			return this.getAutoView();
		}
		else
		{
			return this.getAutoView().addObject("vo", this.orderbService.getById(id));
		}
	}
	/**
	 * 
	 * saveOrUpdate 保存数据
	 * @param orderbPO
	 * @return
	 * @throws Exception
	 *ResultMessage
	 * @exception
	 * @since  1.0.0
	 */
	@RequestMapping("/saveOrUpdate.do")
	@ResponseBody
	public ResultMessage saveOrUpdate(Long orderhId,OrderbVO orderbVO) throws Exception
	{
		orderbVO.setOrderhId(orderhId);
		orderbVO = this.orderbService.saveOrUpdate(orderbVO);
		return new ResultMessage(ResultMessage.Success,"保存成功",orderbVO);

	}



	/**
	 * 
	 * delById 根据ID删除
	 * @param id
	 * @return
	 * @throws Exception
	 *ResultMessage
	 * @exception
	 * @since  1.0.0
	 */
	@RequestMapping("/delById.do")
	@ResponseBody
	public ResultMessage delById(Long id) throws Exception
	{
		this.orderbService.delById(id);
		return new ResultMessage(ResultMessage.Success,"删除成功");
	}

	/**
	 * 
	 * delByIds 根据多个ID字符串删除
	 * @param ids
	 * @return
	 * @throws Exception
	 *ResultMessage
	 * @exception
	 * @since  1.0.0
	 */
	@RequestMapping("/delByIds.do")
	@ResponseBody
	public ResultMessage delByIds(String ids) throws Exception
	{
		this.orderbService.delByIds(ArrayUtil.convertArray(ids.split(",")));
		return new ResultMessage(ResultMessage.Success,"删除成功");
	}

	@RequestMapping("/selector.do")
	public ModelAndView selector() throws Exception {
		return getAutoView();
	} 
	
	
	
	@RequestMapping("/listSendableOrderb.do")
	@ResponseBody
	public List<OrderbPO> listSendableOrderb() throws Exception {
		return orderbService.listSendableOrderb(RequestUtil.getParameterValueMap(request, false,false));
	} 
}
